package net.demo.demo1;

import java.io.IOException;
import java.net.*;
import java.util.Scanner;

public class Udpsend {
    public static void main(String[] args) throws IOException {
        //创建发送数据的对象
        DatagramSocket ds = new DatagramSocket();

        //发送过程
        Scanner sc = new Scanner(System.in);
        while (true){
            System.out.println("输入:");
            String s = sc.nextLine();
            if ("886".equals(s)){
                break;
            }
            byte[] bytes = s.getBytes();
            InetAddress address = InetAddress.getByName("127.0.0.1");
            int port=10086;
            DatagramPacket dp = new DatagramPacket(bytes,bytes.length,address,port);
            ds.send(dp);
        }
        //关闭资源
        ds.close();
    }
}
